package com.ytjj.qmyx.data.amqp.consumer;

import com.alibaba.fastjson.JSONObject;
import com.rabbitmq.client.Channel;
import com.ytjj.common.constants.QueueConstants;
import com.ytjj.qmyx.data.model.mongo.AppEvaluationInfo;
//import com.ytjj.qmyx.data.service.KafkaSendService;
import com.ytjj.qmyx.mall.model.DynamicDto;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.UUID;

@Slf4j
@Component
public class UsersRecordListener {
//    @Autowired
//    private KafkaSendService kafkaSendService;

//    @Transactional(rollbackFor = Exception.class)
//    @RabbitListener(queuesToDeclare = @Queue(value = QueueConstants.USERS_QUEUE, durable = "true"))
//    public void addRecordByHistory(String usersDto, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag, Channel channel) {
//        log.info("收到一条消息users_info消息：" + usersDto+"");
//        try{
//            log.info("sendUsersInfoRecord={}", usersDto);
//            boolean sendStatus = kafkaSendService.sendUsersInfo(usersDto);
//            log.info("sendUsersInfoRecordStatus={}",sendStatus);
//        }catch (Exception e){
//            log.error("发送到kafka错误",e);
//        }
//    }

//    @Transactional(rollbackFor = Exception.class)
//    @RabbitListener(queuesToDeclare = @Queue(value = QueueConstants.USER_FANS_QUEUE, durable = "true"))
//    public void addUserFansRecordByHistory(String usersDto, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag, Channel channel) {
//        log.debug("收到一条消息user_fans_info消息：" + usersDto+"");
//        try{
//            log.debug("sendUserFansRecord={}", usersDto);
//            boolean sendStatus = kafkaSendService.sendUserFansInfo(usersDto);
//            log.debug("sendUserFansRecordStatus={}",sendStatus);
//        }catch (Exception e){
//            log.error("发送到kafka错误",e);
//        }
//    }

//    @Transactional(rollbackFor = Exception.class)
//    @RabbitListener(queuesToDeclare = @Queue(value = QueueConstants.DYNAMIC_HISTORY_QUEUE, durable = "true"))
//    public void addDynamicByHistory(String dynamicDtoStr, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag, Channel channel) {
//        log.info("收到一条消息dynamic_history_info消息：" + dynamicDtoStr + "");
//        try{
//            log.info("sendDynamicHistoryRecord={}", dynamicDtoStr);
//            DynamicDto dto = JSONObject.parseObject(dynamicDtoStr, DynamicDto.class);
//            AppEvaluationInfo appEvaluationInfo = new AppEvaluationInfo();
//            BeanUtils.copyProperties(dto, appEvaluationInfo);
//            if (StringUtils.isEmpty(appEvaluationInfo.getSeq_id())) {
//                appEvaluationInfo.setSeq_id(UUID.randomUUID().toString().replace("-", ""));
//            }
//            boolean sendStatus = kafkaSendService.sendDynamicHistory(JSONObject.toJSONString(appEvaluationInfo));
//            log.info("sendDynamicHistoryRecord result={}",sendStatus);
//        }catch (Exception e){
//            log.error("发送到kafka错误",e);
//        }
//    }

}
